<?php

namespace service;

use Upyun\Config;
use Upyun\Upyun;

/**
 * 又拍云整理
 */
class Upaiyun
{
    /**
     * 上传又拍云
     * @param $uploadPath
     * @param $exe
     * @param $servicePath
     * @param $unlink
     * @return string
     */
    public function uploadUpyun($uploadPath = '', $file_name = '', $servicePath = '')
    {
        // 又拍云配置信息
        $upyun_info   = config('other.upyun');
        // 配置参数，详情请见又拍云官方文档
        $upyun_config = new Config($upyun_info['service_name'], $upyun_info['operator_name'], $upyun_info['operator_password']);
        $upyun_client = new Upyun($upyun_config);   // 实例化又拍云 传入配置参数

        // 上传又拍云
        $file        = fopen($uploadPath, 'r');
        $serviceFile = $servicePath . $file_name;
        $upyun_client->write($serviceFile, $file);

        return $serviceFile;
    }

    /**
     * 删除又拍云上的文件
     * @param string $path  文件路径
     * @throws \Exception
     */
    public function delFileUpyun($path = '')
    {
        // 又拍云配置信息
        $upyun_info   = config('other.upyun');
        // 配置参数，详情请见又拍云官方文档
        $upyun_config = new Config($upyun_info['service_name'], $upyun_info['operator_name'], $upyun_info['operator_password']);
        $upyun_client = new Upyun($upyun_config);   // 实例化又拍云 传入配置参数

        $upyun_client->delete($path);
    }

}

